//package cn.itcast.wanxinp2p.gateway.config;
//
//import cn.itcast.wanxinp2p.common.domain.RestResponse;
//import cn.itcast.wanxinp2p.common.util.JsonUtil;
//import org.springframework.core.io.buffer.DataBuffer;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.MediaType;
//import org.springframework.http.server.reactive.ServerHttpResponse;
//import org.springframework.security.core.AuthenticationException;
//import org.springframework.security.web.server.authentication.HttpBasicServerAuthenticationEntryPoint;
//import org.springframework.stereotype.Component;
//import org.springframework.web.server.ServerWebExchange;
//import reactor.core.publisher.Mono;
//
//import java.nio.charset.Charset;
//@Component
//public class RestOAuth2AuthExceptionEntryPoint extends HttpBasicServerAuthenticationEntryPoint {
//    @Override
//    public Mono<Void> commence(ServerWebExchange serverWebExchange, AuthenticationException e) {
//        ServerHttpResponse response = serverWebExchange.getResponse();
////        response.setContentType("application/json,charset=utf-8");
////        response.setStatus(restResponse.getCode());
////        ObjectMapper objectMapper = new ObjectMapper();
////        objectMapper.writeValue(response.getOutputStream(),restResponse);
//        response.setStatusCode(HttpStatus.OK);
//        response.getHeaders().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
//        String body= JsonUtil.objectTojson(  new RestResponse(HttpStatus.FORBIDDEN.value(),"没有权限"));
//        DataBuffer buffer =  response.bufferFactory().wrap(body.getBytes(Charset.forName("UTF-8")));
//        return response.writeWith(Mono.just(buffer));
//    }
//}
